package com.ynr.common.utils;

public class ResultUtil {

	public static CommonResult returnSuccess(CodeInfoEnum errorCode) {
		return returnSuccess(errorCode, null);
    }
	
	public static CommonResult returnError(CodeInfoEnum errorCode) {
		return returnError(errorCode, null);
    }
	
	public static CommonResult returnSuccess(CodeInfoEnum errorCode, Object data) {
		CommonResult result = getResult(errorCode, data);
		result.setSuccess(true);
        return result;
    }
	
	public static CommonResult returnError(CodeInfoEnum errorCode, Object data) {
		CommonResult result = getResult(errorCode, data);
		result.setSuccess(false);
        return result;
    }
	
	private static CommonResult getResult(CodeInfoEnum errorCode, Object data) {
		CommonResult result = new CommonResult();
        result.setCode(errorCode.getCode());
        result.setInfo(errorCode.getInfo());
        result.setData(data == null ? "":data);
        return result;
	}
}
